import datetime

from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import  User
from django.contrib.contenttypes import generic


class Tribe(models.Model):
    
    slug = models.SlugField(_("slug"), unique=True)
    name = models.CharField(_("name"), max_length=80, unique=True)
    creator = models.ForeignKey(User, verbose_name=_("creator"), related_name="%(class)s_created")
    created = models.DateTimeField(_("created"), default=datetime.datetime.now)
    description = models.TextField(_("description"))
    
    members = models.ManyToManyField(User,
        related_name = "tribes",
        verbose_name = _("members")
    )

    def __unicode__(self):
        return self.name
 
    def get_absolute_url(self):
        return reverse("tribe_detail", kwargs={"group_slug": self.slug})

    def user_is_member(self, user):
        if user in self.members.all():
            return True
        else:
            return False 

